/**
 * 经纬度定义
 */
export class LatLng {
    /**
     * 纬度:y
     */
    latitude: number;

    /**
     * 经度:x
     */
    longitude: number;

    /**
     * 海拔
     */
    altitude: number;


    constructor(latitude: number, longitude: number, altitude?: number) {
        LatLng.check(latitude);

        this.latitude = latitude;
        this.longitude = longitude;
        this.altitude = altitude;
    }

    public reSize(): this {
        if (this.latitude > 90){
            this.latitude = 90;
        }
        if (this.latitude < -90){
            this.latitude = -90
        }
        if (this.longitude > 180){
            this.longitude = 180;
        }
        if (this.longitude < -180){
            this.longitude = -180;
        }

        return this
    }

    private static check(latitude: number) {
        if (latitude > 90 || latitude < -90) {
            console.error("latitude must be between -90 and 90,but now is %d", latitude);
        }
    }
}
